#ifndef _WINDOWWINDOWS_H_
#define _WINDOWWINDOWS_H_

#include <windowsx.h>


class WindowWindows: public WindowInterface
{
public:
  WindowWindows();
  ~WindowWindows();

  bool open(Context* context, InputListener* listener, const char title[], int width, int height );
  void close();

  // show the window (it is initially hidden)

  void show();

  // hide the window

  void hide();

  // check if window is visible?

  bool visible() const;

  // put window in fullscreen mode

  void fullscreen(int width, int height);

  // put window in windowed mode

  void windowed( int width, int height );

  // center the window on the desktop
  // note: has no effect if the window is minimized or maximized

  void center();

  // zoom window

  void zoom( float scale );

  bool isRun() const;

  // window update pumps the message queue

  void update();

  // get the window handle.
  // null if the window failed to initialize.

  WindowHandle handle() const;

  int getWidth() const;
  int getHeight() const;
  bool getActive() const;

  Mode getOutputMode() const;

  // title management

  void title( const char title[] );

  // listener management
  InputListener * listener() const;
protected:

  static LRESULT CALLBACK StaticWindowProc( WindowHandle hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

  LRESULT CALLBACK WindowProc( WindowHandle hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

  // system menu item ids

  enum SystemMenuItems
  {
    MENU_SEPARATOR_A = 1,
    MENU_ZOOM_ORIGINAL,
    MENU_ZOOM_2X,
    MENU_ZOOM_4X,
    MENU_ZOOM_8X,
    MENU_SEPARATOR_B,
    MENU_WINDOWED,
    MENU_FULLSCREEN,
    MENU_SEPARATOR_C,
    MENU_CENTER
  };

  // current zoom level for window

  enum ZoomLevel
  {
    ZOOM_RESIZED,
    ZOOM_ORIGINAL,
    ZOOM_2X,
    ZOOM_4X,
    ZOOM_8X
  };

  // update addition system menu items

  void updateSystemMenu();
private:

  WindowHandle window;					// window handle
  HMENU systemMenu;				// system menu handle
  int width;						// natural window width
  int height;						// natural window height
  bool active;					// true if window is currently active
  bool run;

  Mode mode;						// current window mode (fullscreen or windowed)

  Mouse mouse;					// current mouse input data

  Key translate[256];				// key translation table (win32 scancode -> Key::Code)
  bool down[256];					// key down table (true means key is down)

  HCURSOR arrowCursor;			// handle to system arrow cursor (does not need to be freed)
  HCURSOR nullCursor;				// null cursor when we dont want to see it

  bool centered;					// true if window is centered
  ZoomLevel zoomLevel;			// current zoom level

  Context * context;		// the context interface (must not be null)
  InputListener * _listener;			// the listener interface (may be null)
};

typedef WindowWindows WindowClass;

#endif // _WINDOWWINDOWS_H_
